package app.fugema.shop.main.order.adapter;

import android.view.View;
import android.view.ViewGroup;

import com.base.common.utils.DensityUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.MyLinearLayoutManager;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.imageView.ImageLoaderUtils;
import app.fugema.shop.R;
import app.fugema.shop.databinding.GroupBookingHeadImageItemBinding;
import app.fugema.shop.databinding.GroupBookingListItemBinding;
import app.fugema.shop.main.order.model.SimpleGroupOrderBean;
import app.fugema.shop.main.order.view.GroupBookingDetailActivity;

public class GroupBookingListAdapter extends SingleRecyclerAdapter<SimpleGroupOrderBean, GroupBookingListItemBinding> {

    @Override
    public int getLayoutId()
    {
        return R.layout.group_booking_list_item;
    }


    @Override
    public void onCreateViewHolder(GroupBookingListItemBinding binding, BaseViewHolder viewHolder) {
        super.onCreateViewHolder(binding, viewHolder);

        binding.rvRecyclerView.setLayoutManager(new MyLinearLayoutManager(viewHolder.itemView.getContext(), 0, false));
        binding.rvRecyclerView.setAdapter(new SingleRecyclerAdapter<String, GroupBookingHeadImageItemBinding>() {
            @Override
            public int getLayoutId() {
                return R.layout.group_booking_head_image_item;
            }

            @Override
            public void onBindViewHolder(GroupBookingHeadImageItemBinding binding, int position, String bean) {
                super.onBindViewHolder(binding, position, bean);
                ImageLoaderUtils.loadImage(binding.givHeadImage, bean);
                if (binding.givHeadImage.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.givHeadImage.getLayoutParams();
                    if (position == 0) {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_0);
                    } else {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_f10);
                    }
                    binding.givHeadImage.setLayoutParams(marginLayoutParams);
                }

            }
        });
    }

    @Override
    public void onBindViewHolder(GroupBookingListItemBinding binding, int position, SimpleGroupOrderBean bean) {
        super.onBindViewHolder(binding, position, bean);
        //binding.pbProgress.setMax(3);
        //binding.pbProgress.setProgress(2);
        //binding.rtvCancel.setVisibility(View.GONE);
        //binding.rtvFriend.setVisibility(View.GONE);
        //BuildStatus 10=开团中，-1=成团失败，0=成团中，1=成团成功
        binding.tvNeedTag1.setVisibility(View.VISIBLE);
        switch (bean.getBuildStatus())
        {
            case 10:
                binding.tvStatusText.setText("开团中");
            break;
            case 1:
                binding.tvNeedTag1.setVisibility(View.GONE);
                if (UIUtils.isNotEmpty(bean.getUserIcons()))
                {
                    binding.tvLackPeople.setText(bean.getUserIcons().size()+"人");
                }
                binding.tvStatusText.setText("拼团成功");
                break;
            case 0:
                binding.tvStatusText.setText("成团中");
                break;
            case -1:
                binding.tvStatusText.setText("成团失败");
                break;
        }

        if (binding.rvRecyclerView.getAdapter() instanceof BaseRVAdapter)
        {
            BaseRVAdapter rvAdapter = (BaseRVAdapter) binding.rvRecyclerView.getAdapter();
            if (UIUtils.isNotEmpty(bean.getUserIcons()))
            {
                rvAdapter.setDataList(bean.getUserIcons());
            }
            else
            {
                rvAdapter.clear();
            }
        }
    }

    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, SimpleGroupOrderBean bean)
    {
        super.onItemClick(view, adapter, onclickType, position, bean);
        GroupBookingDetailActivity.start(view.getContext(), bean.getOrderId());
    }
}
